package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.common.dtos.ResponseResult;
import com.zhentao.common.enums.AppHttpCodeEnum;
import com.zhentao.constants.UserThreadLocal;
import com.zhentao.dating.domain.ApUserSocial;
import com.zhentao.dating.dto.ConcernDto;
import com.zhentao.service.ApUserSocialService;
import com.zhentao.mapper.ApUserSocialMapper;
import com.zhentao.user.domain.AppUser;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 86188
* @description 针对表【ap_user_social】的数据库操作Service实现
* @createDate 2024-09-05 19:12:06
*/
@Service
public class ApUserSocialServiceImpl extends ServiceImpl<ApUserSocialMapper, ApUserSocial>
    implements ApUserSocialService{

    @Override
    public ResponseResult concernOperate(ConcernDto dto) {
        if(dto == null || dto.getOperation() == null || dto.getUserId() == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        AppUser appUser = UserThreadLocal.getUserInfo();
        if(dto.getOperation() == 1 ){
            ApUserSocial apUserSocial = new ApUserSocial();
            apUserSocial.setUserId(appUser.getId());
            apUserSocial.setFollowedId(dto.getUserId());
            apUserSocial.setCreateTime(new Date());
            save(apUserSocial);
        }else if(dto.getOperation() == 2){
            LambdaQueryWrapper<ApUserSocial> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ApUserSocial::getUserId,appUser.getId())
                    .eq(ApUserSocial::getFollowedId,dto.getUserId());
            remove(wrapper);
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}




